package com.mediastory.spsserver.users.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.mediastory.spsserver.users.dao.UsersDao;
import com.mediastory.spsserver.users.domain.Users;

/**
 * @author Jaewon Choi
 *
 */

@Repository
public class UsersDaoImpl extends SqlSessionDaoSupport  implements UsersDao {

	public UsersDaoImpl() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public Users selectAuth(String userId) throws Exception {
		// TODO Auto-generated method stub
		Users result = (Users)(getSqlSession().selectOne("Users.select.auth", userId)); 
		return result;
	}

	@Override
	public List<Users> SelectList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer page = (Integer)condition.get("page");
		Integer maxnum = (Integer)condition.get("maxnum");
		
		List<Users> result = null;
		if(page != null && maxnum != null){
			RowBounds rb = new RowBounds(page, maxnum);
			result = getSqlSession().selectList("Users.selectList", condition, rb);
		}else{
			result = getSqlSession().selectList("Users.selectList", condition);
		}
		
		return result;
	}
	
	@Override
	public Integer SelectListTotalCnt(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("Users.selectListTotalCnt", condition);
		return result;
	}

	@Override
	public Users select(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		Users result = (Users)(getSqlSession().selectOne("Users.select", idx)); 
		return result;
	}

	@Override
	public Users insert(Users users) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("Users.insert", users);
		return users;
	}

	@Override
	public Users update(Users users) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Users.update", users);
		return users;
	}

	@Override
	public int delete(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Users.delete", condition);
		return result;
	}

}
